$(init);

function init(){
	$("#genTableGrid").jqGrid(
  	{
		altRows:false,
        url : ctx+"/common/extQuery?sqlid=genTable",
  	    autowidth:true,
        rownumbers: true,
        height:(($(window.document).height())-150),
  	    datatype: "json",    
  		colNames : ['表名称','注释','操作','id'],
		colModel : [ 
			{name : "NAME",index : "NAME",width : 80,sortable:false},
			{name : "COMMENTS",index : "COMMENTS",width : 80,sortable:false},
			{name : "cz",index : "jsmc",width : 50,sortable:false,align:"center",title:false,formatter:function(value,options,row){
				return "<span class='tdcz'>"+
				"<a title='删除' class='small_btn del' href=javascript:deleteGenTable('"+row.ID+"');>删除</a>"+
				"</span>";
			}},
			{name : "ID",index : "ID",hidden:true}
   		],
        prmNames:{
        	rows:"limit"
        },
		jsonReader :{
			root: "message.list",   
		    page: "message.pageNumber",   
		    total: "message.totalPage",
		    records:"message.totalRow"
		},
        loadtext:"<img src="+ctx+"'/static/images/loading.gif'>&nbsp;&nbsp;拼命加载中...",
  		rowNum : 50,
		rowList : [ 50, 100, 150 ],
		pager : "#genTablePager",
  	    mtype: "POST",
		viewrecords : true,
		sortable:false
     });
     //初始化验证
     formValidate("genTableForm");
     //自适应屏幕
     $(window).resize(function(){
     	$("#dmscGrid").setGridWidth($(window).width()*0.99);
     });
}
	
//刷新角色信息
function refreshGenTable(){
	var data = $("#searchForm").getFormJson();
	$("#genTableGrid").setGridParam({"postData":data}).trigger("reloadGrid");
}

//打开新增角色信息弹出框
function openAddTab(){
    qyClose();
	var name = $("#node_type option:selected").val();
	var str = $("#node_type option:selected").html();
	var comments = str.split(":")[1];
	window.parent.openTab(-999,"配置业务表",ctx+"/genTable/genTable/addGenTable?name="+name+"&comments="+comments);
}
//打开新增角色信息弹出框
function openAddGenTable(){
    formReset("genTableForm");
    openGenTable("新增业务表");
}

//打开角色信息
function openGenTable(title){
	qyOpen(title,630,"genTableContent");
}

//删除gentable
function deleteGenTable(id) {
    qyConfirm("确定删除该记录吗？",function(value){
        if(value){
            var result = doService(ctx+"/genTable/genTable/delete","id",id);
            if(result){
                qyAlert("删除成功！",function(){
                    qyClose();
                    refreshGenTable();
                });
            }
        }
    });
}